<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\user\controller;

use cmf\controller\AdminBaseController;
use think\Db;
/**
 * Description of UserEditController
 *
 * @author Administrator
 */
class UserEditController extends AdminBaseController{
    public function edit(){
        $id     = $this->request->param('id', 0, 'intval');
        $user = Db::name('user')->where('id', $id)->find();
        $server = Db::name('server_cfg')->field('serverid,servername')->select();
        $this->assign('server',$server);
        $this->assign($user);
        return $this->fetch();
    }
    
    public function doPost(){
        $data = $this->request->param();
        $fields = ['id','coin','user_status','serverid'];
        $sdata = [];
        foreach ($fields as $val){
            $sdata [$val] = $data[$val];
        }
        if($sdata['serverid']){
            $server = Db::name('server_cfg')->field('serverid,serverurl')->find($sdata['serverid']);
        }
        if(empty($server)){
            $this->error('服务器ID错误');
        }
        $sdata['user_url'] = $server['serverurl'];
        Db::name('user')->update($sdata);
        $this->success('保存成功');
    }
}
